#ifndef __USER_SYSTEM_H
#define __USER_SYSTEM_H

#define TRUE (!0)
#define FALSE (0)
#define BR9600_PRESET   800
#define BR9600_RELOAD   90     //50~130
#define LED_GPIO_PORT  (GPIOC)
#define LED_GPIO_PINS  (GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_3 | GPIO_PIN_5)
#define KEY_GPIO_PORT  (GPIOD)
#define KEY_GPIO_PINS  (GPIO_PIN_4)
  /*
  ******************************************************************************
  * @attention
  *
  *     key     :i < mannual control
  *     DC_AD   :i < load voltage
  *     BATT_AD :i < battery voltage
  *     CHRG#   :i < Low indicate in charging
  *     DONE#   :i < Low indicate charge finish
  *     DCOK    :o > Low shutdown charge-forward
  *     CH_EN   :o > Low shutdown charger
  *     BATT_OUT:o > High open power output
  *     PWRKEY  :o > launch MC20-modem
  *
  ******************************************************************************
  */ 
#define PMA_GPIO_PORT  (GPIOA)
#define PM_BATT_OUT_PINS  (GPIO_PIN_3)
#define PM_DCOK_PINS  (GPIO_PIN_1)

#define PMB_GPIO_PORT  (GPIOB)
#define PM_CHRG_PINS  (GPIO_PIN_4)

#define MC20_GPIO_PORT  (GPIOC)
#define MC20_PWRK_PINS  (GPIO_PIN_4)

#define SOFT_SEND_PORT  (GPIOD)
#define SOFT_SEND_PINS  (GPIO_PIN_2)
      
#define UART_FIFO_SIZE  16
#define SOFT_SEND_FFSZ  208
#define KEY_DEB_REP_TIMES 6
#define REMOTE_CHECK_FREQ_DIV   0 //0:1min15sec, 1:2min30sec, 2:3min45sec(4min), 3:5min(5min20sec)
#define SMS_TXT_BUF_LIMIT 45
#define VENDOR_ID_F     'h'
#define VENDOR_ID_B     'x'
/* Public functions ----------------------------------------------------------*/
void waitn(uint16_t nCount);
void waits(uint16_t nCount);
void adc_config(uint8_t mod);
//void adc_monitor(void);
void adc_monitor2(void);
void uart_recv_monitor(void);
void soft_send_monitor(void);
void fifo_init(void);
int8_t fifo_addin(uint8_t dat, uint8_t *idx, uint8_t *odx, uint8_t *fifoaddr, uint8_t fifosize);
int8_t fifo_getout(uint8_t *dat, uint8_t *idx, uint8_t *odx, uint8_t *fifoaddr, uint8_t fifosize);

void softimer_init(void);
//void event_alarm_init(void);
//void event_alarm_trig(void);
//void event_alarm_set(uint8_t n);

void key_init(void);
void getkeycode(void);
void rilinit(void);
void rilloop(void);
/* Private functions ---------------------------------------------------------*/
uint8_t getfunckey(void);
void digit2char(uint8_t* ch);
int8_t soft_send_byte(uint8_t data);
int8_t send2console(uint8_t *data, uint8_t n);
int8_t send2consoleb(uint8_t data);
int8_t send2uart_device(uint8_t *data, uint8_t n);
#endif